package com.tanhua.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.db.mapper.AttentionListMapper;
import com.tanhua.dubbo.api.AttentionApi;
import com.tanhua.model.pojo.AttentionList;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class AttentionApiImpl implements AttentionApi {

    @Autowired
    private AttentionListMapper attentionListMapper;

    //查询关注信息
    @Override
    public AttentionList findById(Long userId, String uid) {
        LambdaQueryWrapper<AttentionList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttentionList::getUserId,uid);
        queryWrapper.eq(AttentionList::getAttentionId,userId);
        AttentionList attentionList = attentionListMapper.selectOne(queryWrapper);
        return attentionList;
    }

    //保存关注信息
    @Override
    public void save(Long userId, String uid) {
        AttentionList attentionList = new AttentionList();
        attentionList.setUserId(Long.parseLong(uid));
        attentionList.setAttentionId(userId);
        attentionListMapper.insert(attentionList);
    }

    //删除关注信息
    @Override
    public void delete(Long userId, String uid) {
        attentionListMapper.delete(Wrappers.lambdaQuery(AttentionList.class).eq(AttentionList::getUserId,uid).eq(AttentionList::getAttentionId,userId));
    }

    //查询粉丝
    @Override
    public List<AttentionList> findCounts(Long userId) {
        LambdaQueryWrapper<AttentionList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttentionList::getAttentionId,userId);
        List<AttentionList> attentionLists = attentionListMapper.selectList(queryWrapper);
        return attentionLists;
    }
}
